import sys

sys.path.append("..")
from utils import get_connection

# credient = pika.PlainCredentials(username='admin', password='admin')
# connection = pika.BlockingConnection(
#     pika.ConnectionParameters(host='0.0.0.0', port=5672, virtual_host='/', credentials=credient))
connection = get_connection()

channel = connection.channel()
channel.exchange_declare(exchange='topic_exchange', exchange_type='topic', durable=True)
channel.queue_declare(queue='topic_queue1', durable=True, auto_delete=True)

channel.queue_bind(exchange='topic_exchange', queue='topic_queue1', routing_key='like.#')  # routing_ke队列指定以什么规则绑定交换和队列


def callback(channel, method, properity, body):
    channel.basic_ack(delivery_tag=method.delivery_tag)
    print(body.decode())


channel.basic_qos(prefetch_count=1)
channel.basic_consume(on_message_callback=callback, queue='topic_queue1')
channel.start_consuming()
